import Dialog from '@vant/weapp/dialog/dialog';
import api from '../../utils/api.js'
const app = getApp()
Page({
  data: {
    show: false,
    userName: '',
    userId: '',
  },
  onShow () {
    app.globalData.selected = 3;
  },
  handleRelieve () {
    Dialog.confirm({
      title: '温馨提示',
      message: '是否确认解除与微信绑定？',
    })
      .then(() => {
        api.Unbinding().then((res) => {
          if (res.root.response.errcode == 0) {
            const perData = {
              userName: '',
              userId: '',
              token: ''
            }
            wx.setStorageSync('personalInfo', perData)
            app.globalData.selected = 0
            wx.showToast({
              title: res.root.response.errmsg,
              duration: 2000,
              icon: 'none',
              complete: () => {
                setTimeout(() => {
                  wx.reLaunch({
                    url: '/repairPages/service_login/service_login'
                  })
                }, 1500)
              }
            })
          }
        })
      })
  },

  handleQuit () {
    Dialog.confirm({
      title: '温馨提示',
      message: '是否确认退出该账号？',
    })
      .then(() => {
        const perData = {
          userName: '',
          userId: '',
          token: ''
        }
        wx.setStorageSync('personalInfo', perData)
        app.globalData.selected = 0
        wx.reLaunch({
          url: '/repairPages/service_login/service_login'
        })
      })
  },
  onShow () {
    if (wx.getStorageSync('personalInfo')) {
      const perInfo = wx.getStorageSync('personalInfo')
      this.setData({ userName: perInfo.userName, userId: perInfo.userId })
    }
  },
})
